package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import model.Pais;

public class PaisDaoImpl implements PaisDao {

	Connection c;
	
	public PaisDaoImpl(){
		GenericDao gDao = new GenericDao();
		c = gDao.getConnection();
	}

	
	@Override
	public List<Pais> listaPaises() throws SQLException {
		List<Pais> listaPais = new ArrayList<Pais>();
		String sql = "SELECT id, nome FROM pais";
		PreparedStatement ps = c.prepareStatement(sql);
		ResultSet rs = ps.executeQuery();
		while (rs.next()){
			Pais p = new Pais();
			p.setId(rs.getInt("id"));
			p.setNome(rs.getString("nome"));
			listaPais.add(p);
		}
		rs.close();
		ps.close();
		return listaPais;

	}

}
